<?php
/**
 * 用户控制器
 */

namespace app\admin\controller;

use think\Request;
use app\common\model\User;
use app\common\model\ShopConfig;
use app\admin\logic\UserLogic;
use app\common\server\ConfigServer;
use think\Db;
class UserController extends Controller
{
    /**
     * 会员列表
     */
    public function index(){
        if ($this->request->isAjax()) {
            $get = $this->request->get();
            $list=UserLogic::lists($get);
            return json([
                'code' =>1,
                'msg'  =>'',
                'data' =>$list,
            ]);

        }
        return $this->fetch();
    }
    
    /*
     * 会员编辑
     */
    public function edit($id){
        if($this->request->isAjax()){
            $post = $this->request->post();
            $result = $this->validate($post,'app\admin\validate\User');
            if($result === true){
                UserLogic::edit($post);
                return success('保存成功');
            }
            return error($result);
        }
        $detail = UserLogic::getUser($id,true);
        $this->assign('info',$detail);
        return $this->fetch();
    }

    public function info(){
        $id = $this->request->get('id', '', 'intval');
        $detail = UserLogic::getInfo($id);
        $this->assign('detail',$detail);
        return $this->fetch();
    }

    public function fans()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post();
            $result = UserLogic::fans($params);
            return json([
                'code' =>1,
                'msg'  =>'',
                'data' =>$result,
            ]);
        }
        $id = $this->request->get('id/d');
        $this->assign('id',$id);
        return $this->fetch();
    }


     /**
     * 账户调整
     * @param $id
     * @return mixed
     */
    public function adjustAccount($id){
        if ($this->request->isAjax()) {
            $post = $this->request->post();
            $result = $this->validate($post,'app\admin\validate\AdjustAccount');
            if($result === true){
                $result = UserLogic::adjustAccount($post); //逻辑层处理信息
                if($result){
                    return success('操作成功',$result);
                }
                $result = '操作失败';
            }
            return error($result);

        }
        $this->assign('info',UserLogic::getUser($id));
        return $this->fetch();
    }




    public function userLists()
    {
        if ($this->request->isPost()) {
            $params = $this->request->post();
            $lists = UserLogic::userLists($params);
            return json([
                'code' =>1,
                'msg'  =>'',
                'data' =>$lists
            ]);
        }
        return $this->fetch();
    }
}
